#region Microsoft Public License
/*
 * (c) Copyright Chenjun Wu. http://utablesdk.codeplex.com
 * 
 * This source is subject to the Microsoft Public License (Ms-PL).
 * Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
 * All other rights reserved.
 */
#endregion

﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;

namespace UTable.Objects.Controls
{
    internal class UGridImpl : UPanelImpl
    {
        private Grid _owner;
        public UGridImpl(Grid owner): base(owner)
        {
            this.ChildrenChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(UGridImpl_ChildrenChanged);
            _owner = owner;
        }

        void UGridImpl_ChildrenChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            // reset the z index for the children
            for (int i=0; i<_owner.Children.Count; i++)
            {
                if (_owner.Children[i] is IControl)
                {
                    IControl c = _owner.Children[i] as IControl;
                    lock (c.Info)
                    {
                        c.Info.ZIndex = i;
                    }
                }
            }
        }
    }
}
